import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Io3 {

    public static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        ArrayList<String> result = new ArrayList<>();
        System.out.println("请输入要扫描的目录路径");
        String lujing = scanner.next();
        File root = new File(lujing);
        if (!root.isDirectory()) {
            System.out.println("输入的路径有误");
        }
        System.out.println("请输入指定的字符");
        String aim = scanner.next();
        digui(root, result, aim);
        for (int j = 0; j < result.size(); j++) {
            System.out.println(result.get(j));
        }


    }

    public static void digui(File root, ArrayList<String> result, String aim) {
        File[] files = root.listFiles();
        if (files == null) {
            return;
        }
        for (File file : files) {
            if (file.isDirectory()) {
                digui(file, result, aim);

            } else {
                if (file.getName().contains(aim) || duqu(file, aim)) {
                    result.add(file.getName());

                }
            }
        }
    }

    public static boolean duqu(File file, String aim) {
        ArrayList<Character> b = new ArrayList<>();

        try (Reader reader = new FileReader(file)) {
            while (true) {
                int a = reader.read();
                if (a == -1) {
                    break;
                }
                b.add((char) a);


            }
            int i = 0;
            for (i = 0; i < aim.length(); i++) {
                char ch = aim.charAt(i);
                if (!b.contains(ch)) {
                    return false;

                }
            }
            //return true;


        } catch (IOException e) {
            e.printStackTrace();
        }
        return true;

    }
}
